package com.sanbi.erp.api.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class Swagger2Configuration {
    @Bean
    public Docket docket(Environment environment) {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("erp")
                .apiInfo(apiInfo())
                .enable(environment.acceptsProfiles(Profiles.of("dev", "local", "demo", "test")))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sanbi.erp.api.web"))
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("easytao-erp API")
                .description("easytao erp api")
                .termsOfServiceUrl("https://github.com/sanbi/easytao")
                .contact("Easytao Tech")
                .version("1.0")
                .build();
    }
}
